//
//  WOFile.m
//  WOPrototype
//
//  Created by Alexander Skogberg on 2010-04-15.
//  Copyright 2010 Chalmers tekniska högskola. All rights reserved.
//

#import "WOFile.h"

@implementation WOFile

@synthesize fileName;
@synthesize fileURLPath;
@synthesize fileHomePath;
@synthesize fileType;
@synthesize fileIcon;

-(id) initWithFileName:(NSString *) aFileName 
		   fileURLPath:(NSString *) aFileURLPath
{
	if(self = [super init])
	{
		self.fileName = aFileName;
		self.fileURLPath = aFileURLPath;
		self.fileHomePath = nil;
		self.fileType = [[aFileName componentsSeparatedByString: @"."] lastObject];
		self.fileIcon = [self setFileTypeIcon:self.fileType];
	}
	return self;
}

/* Assigning the right image icon depending on file type */
-(UIImage *) setFileTypeIcon:(NSString *) aFileType
{
	UIImage *theImage = nil;
	
	if([aFileType isEqualToString:@"txt"])
	{
		theImage = [UIImage imageNamed:@"file_txt.png"];
	}
	else if([aFileType isEqualToString: @"rtf"]) 
	{
		theImage = [UIImage imageNamed:@"file_rtf.png"];
	}
	else if([aFileType isEqualToString: @"doc"] || [aFileType isEqualToString: @"docx"]) 
	{
		theImage = [UIImage imageNamed:@"file_doc.png"];
	}
	else if([aFileType isEqualToString: @"ppt"]) 
	{
		theImage = [UIImage imageNamed:@"file_ppt.png"];
	}
	else if([aFileType isEqualToString: @"pdf"]) 
	{
		theImage = [UIImage imageNamed:@"file_pdf.png"];
	}
	else if([aFileType isEqualToString: @"jpg"] || [aFileType isEqualToString: @"jpeg"]) 
	{
		theImage = [UIImage imageNamed:@"file_jpg.png"];
	}
	else if([aFileType isEqualToString: @"png"]) 
	{
		theImage = [UIImage imageNamed:@"file_png.png"];
	}
	else if([aFileType isEqualToString: @"xls"] || [aFileType isEqualToString: @"xlsx"]) 
	{
		theImage = [UIImage imageNamed:@"file_xls.png"];
	}
	return theImage;
}

@end
